import { createRouter, createWebHashHistory } from "vue-router";

// 所有的路由
export const routes = [
  {
    path: "/:pathMatch(.*)",
    redirect: "/main/city",
    isMenu: false,
  },
  {
    path: "/login",
    name: "login",
    isMenu: false,
    component: () =>
      import(/* webpackChunkName:'mycomp' */ "@src/views/login/index.vue"),
  },
  {
    path: "/main",
    name: "Cesium",
    isMenu: true,
    redirect: "/main/city",
    children: [
      {
        path: "city",
        name: "智慧城市场景",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/main/city/index.vue"
          ),
      },
      {
        path: "meteorological",
        name: "气象数据展示",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/main/meteorological/index.vue"
          ),
      },
      {
        path: "primitive",
        name: "自定义primitive",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/main/primitive/index.vue"
          ),
      },
      // {
      // 	path: "test_cesium",
      // 	name: "试验场_cesium",
      // 	component: () =>
      // 		import(
      // 			/* webpackChunkName:'mycomp' */ "@src/views/main/test/index.vue"
      // 		),
      // },
    ],
    component: () =>
      import(/* webpackChunkName:'mycomp' */ "@src/views/main/index.vue"),
  },
  {
    path: "/webgl",
    name: "webgl",
    isMenu: true,
    redirect: "/webgl/radar",
    children: [
      {
        path: "radar",
        name: "雷达图绘制",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/webgl/radar/index.vue"
          ),
      },
      {
        path: "juanlian",
        name: "卷帘",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/webgl/juanlian/index.vue"
          ),
      },
    ],
    component: () =>
      import(/* webpackChunkName:'mycomp' */ "@src/views/webgl/index.vue"),
  },
  {
    path: "/threejs",
    name: "threejs",
    isMenu: true,
    redirect: "/threejs/test",
    children: [
      {
        path: "test_threejs",
        name: "试验场_threejs",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/threejs/test/index.vue"
          ),
      },
      {
        path: "tank",
        name: "坦克-场景图",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/threejs/tank/index.vue"
          ),
      },
    ],
    component: () =>
      import(/* webpackChunkName:'mycomp' */ "@src/views/webgl/index.vue"),
  },
  {
    path: "/web",
    name: "web",
    isMenu: true,
    meta: {
      key: "web",
      name: "web",
    },
    redirect: "/web/table",
    children: [
      {
        path: "test_web",
        name: "试验场_web",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/web/test/index.vue"
          ),
      },
      {
        path: "table",
        name: "虚拟表格",
        component: () =>
          import(
            /* webpackChunkName:'mycomp' */ "@src/views/web/table/index.vue"
          ),
      },
    ],
    component: () =>
      import(/* webpackChunkName:'mycomp' */ "@src/views/web/index.vue"),
  },
];

// 创建的路由示例
export const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes,
});

// 路由守卫，如果未登录，强制跳转到登录页
// router.beforeEach((to, from, next) => {
// 	if (to.path === '/login') {
// 		//登录页，清除token后跳转
// 		window.sessionStorage.removeItem('token');
// 		next();
// 	} else {
// 		if (window.sessionStorage.getItem('token')) {
// 			//有token可跳转
// 			next();
// 		} else {
// 			//有token跳至登录页
// 			// message.warn({
// 			// 	content: '请先登录',
// 			// 	duration: 2,
// 			// 	onClick: () => message.destroy(),
// 			// })
// 			next({ path: '/login' });
// 		}
// 	}
// });
